package com.mj.mafeed.util;


import com.mj.mafeed.config.Constants;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * SQLite数据库工具类
 * @author zhaominglei
 * @date 2014-12-10
 * 
 */
public class DBHelper extends SQLiteOpenHelper {
	private static DBHelper instance;
	
	private DBHelper(Context context) {
		super(context, Constants.DB_NAME, null, Constants.DB_VERSION);
	}
	public synchronized static DBHelper getInstance(Context context) {
		if (instance == null) {
			instance = new DBHelper(context);
		}
		return instance;
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("create table if not exists feed_mobile_index(mobileindexid integer primary key,orders integer,title varchar(255),source varchar(255),type integer,url varchar(255),price decimal(21,6),promotionprice decimal(21,6),productid integer)");
		db.execSQL("create table if not exists feed_product_category(productCategoryId integer primary key,orders integer,grade integer,name varchar(255),source varchar(255),seoDescription varchar(255),seoKeywords varchar(255),seoTitle varchar(255),treePath varchar(255),parentId integer,appImage varchar(255))");
		db.execSQL("create table if not exists feed_product(productid integer primary key,sn varchar(100),name varchar(255),price decimal(21,6),stock integer,imageurl varchar(255),memo varchar(255),introduction text,issell integer,weight integer)");
		db.execSQL("create table if not exists feed_cart_item(cartitemid integer primary key autoincrement,cartid integer,productid integer not null,quantity integer not null,sn varchar(100),name varchar(255),price decimal(21,6),stock integer,imageurl varchar(255))");
		db.execSQL("create table if not exists feed_area(areaid integer primary key,orders integer default null,fullname text not null,name varchar(100) not null,treepath varchar(255) not null,parentid integer default null)");
		db.execSQL("create table if not exists feed_shipping_method(shippingmethodid integer primary key,orders integer default null,continueprice decimal(21,6),continueweight integer,description text,firstprice decimal(21,6),firstweight integer,icon varchar(255) default null,name varchar(255) not null)");
		db.execSQL("create table if not exists feed_payment_method(paymentmethodid integer primary key,orders integer default null,content text,description varchar(255) default null,icon varchar(255) default null,method integer not null,name varchar(255) not null,timeout int(11) default null)");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	}

}
